package com.itzol.service.impl;

import com.itzol.entity.Category;
import com.itzol.mapper.CategoryMapper;
import com.itzol.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itzol.uitls.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 分类表 服务实现类
 * </p>
 *
 * @author linxin
 * @since 2022-03-09
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;
    //新增分类
    @Override
    public Result addCategory(Category category) {
        int i= categoryMapper.insert(category);
        if(i>0){
            return Result.succ("新增成功");
        }
        return Result.fail("新增失败");
    }

    //删除分类
    @Override
    public Result deleteCategory(Integer id) {
        int i= categoryMapper.deleteById(id);
        if(i>0){
            return Result.succ("删除成功");
        }
        return Result.fail("删除失败");
    }
    //获取全部分类
    @Override
    public Result getCategory() {
        return Result.succ(categoryMapper.selectList(null));
    }

    //修改分类
    @Override
    public Result editorCategory(Category category) {
        int i=categoryMapper.updateById(category);
        if(i>0){
            return Result.succ("修改成功");
        }
        return Result.fail("修改失败");
    }

}
